package com.topideal.supplychain.hades.rest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author wanwei
 * @TODO 海关申报指令接口
 * 
 *       上游下发海关信息给我们，根据 订阅者加订单编号与推送物流系统的订单信息进行匹配，如无匹配数据，将返回失败；
 * @date: 2017年10月9日 上午9:24:39
 */
@Controller
@RequestMapping("/rest/declare")
public class DeclareRestService {

	/*private static final Logger logger = Logger.getLogger(DeclareRestService.class);
	@Autowired
	private TskDeclareService tskDeclareService;

	@Autowired
	private ExpInvokeLogService expInvokeLogService;

	@RequestMapping(value = "/sendReq", method = RequestMethod.POST)
	@ResponseBody
	public IFResponseDto sendReq(@RequestBody BillDeclareDto billDeclareDto, HttpServletRequest request) {
		ExpInvokeLog expInvokeLog = new ExpInvokeLog(ExpCodeEnum.TMS012, IpAddressUtil.getIpAddress(request),
				SourceEnum.TMS.getCode(), IpAddressUtil.getLoalhostIP(), new Date(),
				JacksonUtil.toJSon(billDeclareDto));
		TskDeclare tskDeclare = new TskDeclare();
		IFResponseDto iFResponseDto = new IFResponseDto();
		try {
			// 校验参数
			checkForParam(billDeclareDto);
			BeanUtils.copyProperties(billDeclareDto, tskDeclare);
			// 指令处理
			String notes = tskDeclareService.createDeclareBillInfo(tskDeclare);
			iFResponseDto.setStatus(SuccessFailureEnum.SUCCESS.getValue());
			iFResponseDto.setNotes(notes);
			expInvokeLog.setIsSuccess(SuccessFailureEnum.SUCCESS);
		} catch (BusinessException e) {
			iFResponseDto.setStatus(SuccessFailureEnum.FAILURE.getValue());
			iFResponseDto.setNotes(e.getMessage());
			logger.error("处理海关申报请求失败:" + e.getMessage(), e);
		} catch (Exception e) {
			iFResponseDto.setStatus(SuccessFailureEnum.FAILURE.getValue());
			iFResponseDto.setNotes(Throwables.getStackTraceAsString(e));
			logger.error("处理海关申报请求失败:" + e.getMessage(), e);
		} finally {
			expInvokeLog.setTraceId(billDeclareDto.getOutOrderCode()).setSource(billDeclareDto.getSubscriberCode())
					.setPlatformOrderCode(billDeclareDto.getPlatformOrderCode())
					.setOriginalCode(billDeclareDto.getSubscriberCode() + billDeclareDto.getOutOrderCode())
					.setResponseData(JacksonUtil.toJSon(iFResponseDto)).setEndTime(new Date());
			expInvokeLogService.insertExpInvokeLog(expInvokeLog, false);
		}
		return iFResponseDto;
	}

	private void checkForParam(BillDeclareDto billDeclareDto) {
		if (billDeclareDto == null) {
			throw new BusinessException("请求参数异常：解析为空");
		}
		if (StringUtils.isEmpty(billDeclareDto.getOutOrderCode()) || StringUtils.isEmpty(billDeclareDto.getCarrierCode())
				|| StringUtils.isEmpty(billDeclareDto.getSubscriberCode())
				|| StringUtils.isEmpty(billDeclareDto.getPlatformOrderCode())
				|| StringUtils.isEmpty(billDeclareDto.getShipmentCode())) {
			throw new BusinessException("参数异常 ");
		}
	}*/
}
